package com.cqust.service;

import com.cqust.entity.User;
import com.cqust.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    private UserMapper usermapper;

    @Autowired
    private UserMapper userMapper;
    public int register(User user) {
        // TODO: implement user registration
        if (userMapper.ExistUser(user)!= null) {
            System.out.println("用户已存在"+userMapper.ExistUser(user));
            return 0;
        }

        user.setuId(String.valueOf(userMapper.getMaxId()+1));
        int flag = userMapper.insert(user);
        System.out.println("注册成功");
        return flag;
    }
    public List<User> getUsers() {
        List<User> users = usermapper.selectAll();
        return users;
    }


    public User login(User user) {
        User user1 = usermapper.ExistUser(user);
        return user1;
    }

    public int updateUser(User user) {
        return userMapper.updateUser(user);
    }

    public int deleteUserById(int uId) {
        return userMapper.deleteUserById(uId);
    }

    public int deleteCardByUid(int uId) {
        return userMapper.deleteCardByUid(uId);
    }
}
